package com.dreamer.domain.mall.transfer;


import com.dreamer.domain.user.Agent;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hxf
 */
public class TransferVo {

    private Integer fid;

    private Integer tid;


    private String fromUser;

    private String toUser;

    private String date;

    private String remi;

    private String remark;



    //上级
    private String parentUser;

    private List<ItemVO> itemVOs = new ArrayList<>();

    public Integer getFid() {
        return fid;
    }

    public void setFid(Integer fid) {
        this.fid = fid;
    }

    public Integer getTid() {
        return tid;
    }

    public void setTid(Integer tid) {
        this.tid = tid;
    }

    public String getParentUser() {
        return parentUser;
    }

    public void setParentUser(String parentUser) {
        this.parentUser = parentUser;
    }

    /**
     * 进货级别
     */
    private Integer addLevel;

    /**
     * 0是退货  1是进货
     */
    private Integer add;

    private String item = "";

    public String getRemi() {
        return remi;
    }

    public void setRemi(String remi) {
        this.remi = remi;
    }

    public List<ItemVO> getItemVOs() {
        return itemVOs;
    }

    public void setItemVOs(List<ItemVO> itemVOs) {
        this.itemVOs = itemVOs;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getItem() {
        return item;
    }

    public Integer getAddLevel() {
        return addLevel;
    }

    public void setAddLevel(Integer addLevel) {
        this.addLevel = addLevel;
    }

    public Integer getAdd() {
        return add;
    }

    public void setAdd(Integer add) {
        this.add = add;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public String getFromUser() {
        return fromUser;
    }

    public void setFromUser(String fromUser) {
        this.fromUser = fromUser;
    }

    public String getToUser() {
        return toUser;
    }

    public void setToUser(String toUser) {
        this.toUser = toUser;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public TransferVo(Transfer transfer, Integer add, Integer addLevel) {
        this.fromUser = transfer.getFromAgent().getRealName() + "--" + transfer.getFromAgent().getAgentCode();
        this.toUser = transfer.getToAgent().getRealName() + "--" + transfer.getToAgent().getAgentCode();
        this.date = new SimpleDateFormat("yyyy-MM-dd").format(transfer.getUpdateTime());
        this.add = add;
        this.addLevel = addLevel;
        this.remi = transfer.getRemittance();
        this.remark = transfer.getRemark();
        this.fid = transfer.getFromAgent().getId();
        this.tid = transfer.getToAgent().getId();
        if (addLevel == 2) {
            if (add == 1) {
                parentUser = transfer.getToAgent().getParent().getRealName() + "--" + transfer.getToAgent().getParent().getAgentCode();
            } else {
                parentUser = transfer.getFromAgent().getParent().getRealName() + "--" + transfer.getFromAgent().getParent().getAgentCode();
            }
        }
        Agent temAgent = transfer.getToAgent();
        if (add == 0) {
            temAgent = transfer.getFromAgent();
        }
        final  Agent a = temAgent;
        transfer.getItems().forEach(item -> {
            String voucherStr = item.getGoods().getPrice(a.getMainLevel(item.getGoods())).getVoucherStr();
            this.item += item.getGoods().getName() + "X" + item.getQuantity() + "  ";
            ItemVO itemVO = new ItemVO(item.getGoods().getId(), item.getGoods().getName(), item.getQuantity(), voucherStr);
            this.getItemVOs().add(itemVO);
        });
    }

    public TransferVo() {

    }
}

class ItemVO {


    private Integer id;

    private String name;

    private Integer quantity;

    private Double v1;

    private Double v2;

    public ItemVO(Integer id, String name, Integer quantity, String vs) {
        this.id = id;
        this.name = name;
        this.quantity = quantity;
//        v1 = Double.parseDouble("2");
//        v2 = Double.parseDouble("1");
        v1 = Double.parseDouble(vs.split("_")[0]);
        v2 = Double.parseDouble(vs.split("_")[1]);
    }

    public Double getV(int addLevel) {
        if (addLevel == 1) {
            return v1;
        } else {
            return v2;
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Double getV1() {
        return v1;
    }

    public void setV1(Double v1) {
        this.v1 = v1;
    }

    public Double getV2() {
        return v2;
    }

    public void setV2(Double v2) {
        this.v2 = v2;
    }
}
